/**
 * Apr 11, 2012
 */
package org.zlex.spring.orm.ibatis.dao.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.orm.ibatis.SqlMapClientTemplate;
import org.springframework.stereotype.Repository;
import org.zlex.spring.orm.ibatis.dao.UserDao;
import org.zlex.spring.orm.ibatis.domain.User;

/**
 * 
 * @author zlex
 * @version 1.0
 * @since 1.0
 */
@Repository("userDao")
public class UserDaoImpl implements UserDao {
	@Autowired
	private SqlMapClientTemplate sqlMapClientTemplate;

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.zlex.spring.orm.ibatis.dao.UserDao#readList()
	 */
	@SuppressWarnings("unchecked")
	@Override
	public List<User> readList() {
		return (List<User>) sqlMapClientTemplate.queryForList("User.readList");
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.zlex.spring.orm.ibatis.dao.UserDao#read(java.lang.String)
	 */
	@Override
	public User read(String username) {
		return (User) sqlMapClientTemplate.queryForObject(
				"User.readByUsername", username);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.zlex.spring.orm.ibatis.dao.UserDao#update(int)
	 */
	@Override
	public void update(int id, String username) {
		sqlMapClientTemplate.delete("User.update", new User(id, username));
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.zlex.spring.orm.ibatis.dao.UserDao#delete(int)
	 */
	@Override
	public void delete(int id) {
		sqlMapClientTemplate.delete("User.delete", id);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * org.zlex.spring.orm.ibatis.dao.UserDao#create(org.zlex.spring.orm.ibatis
	 * .domain.User)
	 */
	@Override
	public int create(User user) {
		return (Integer) sqlMapClientTemplate.insert("User.insert", user);
	}

}
